<?php
namespace App\Utils;

use App\Models\RechargeOrder;
use Overtrue\LaravelWeChat\Facade;

/**
 * Class WxTemplate
 * @package App\Utils
 * @author  zjw
 * 小程序 模板消息工具类
 */
class WxTemplate{
    /**
     * @param RechargeOrder $order
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     */
    public static function sendMpRecharge(RechargeOrder $order){
        if (($tpl =  config('wechat.mini_program.default.recharge_tpl')) && $order->user->wx_openid) {
            Facade::miniProgram()->template_message->send([
                'touser' => $order->user->wx_openid,
                'template_id' => $tpl,
                'pages' => 'pages/index/main',
                'form_id' => $order->prepay_id,
                'data' => [
                    'keyword1' => $order->recharge_price,
                    'keyword2' => '充值成功',
                    'keyword3'=>$order->user->balance,
                    'keyword4'=> '不要忘记为你的孩子订餐哦'
                ],
            ]);
        }
    }
}
